package nsu.edu.zsq.common;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import nsu.edu.zsq.filter.AclControlFilter;
import nsu.edu.zsq.filter.LoginFilter;

/** 
* Description: 多个拦截器的配置文件（设置拦截路径、优先级等）<br>
*/
@Configuration
public class FilterConfig {
    
  @Bean
  public FilterRegistrationBean<LoginFilter> loginFilterRegistration() {
      FilterRegistrationBean<LoginFilter> filterRegistration = new FilterRegistrationBean<LoginFilter>();
      filterRegistration.setFilter(new LoginFilter());
      filterRegistration.addUrlPatterns("/sys/*","/student/*", "/teacher/*", "/toIndex");
      // 添加默认参数,key:value（可以在controller中自动注入该bean，然后获取到这个参数）
      // filterRegistration.addInitParameter("name", "value");
      filterRegistration.setName("loginFilter");
      // 设置过滤器的优先级（值越小，优先级越高）
      filterRegistration.setOrder(Integer.MAX_VALUE - 10);
      return filterRegistration;
  }

  @Bean
  public FilterRegistrationBean<AclControlFilter> aclControlFilterRegistration() {
      FilterRegistrationBean<AclControlFilter> filterRegistration = new FilterRegistrationBean<AclControlFilter>();
      filterRegistration.setFilter(new AclControlFilter());
      filterRegistration.addUrlPatterns("/sys/*");
      filterRegistration.setName("aclControlFilter");
      // 设置过滤器的优先级
      filterRegistration.setOrder(Integer.MAX_VALUE - 8);
      return filterRegistration;
  }
}
